package com.pyl.admin.core.web;

import com.pyl.core.utils.HttpServletUtil;

/**
 * @author 灵魂贰婶
 * @date 2019/07/12
 */
public class PageUtil {
	private static final Integer pageSizeDef = 50;
	private static final String orderByColumnDef = "update_date";
	private static final String isAscDef = "DESC";

	/**
	 * 创建分页排序对象
	 *
	 * @param pageSizeDef      分页数据数量默认值
	 * @param orderByColumnDef 排序字段名称默认值
	 * @param isAscDef         排序方式默认值
	 */
	public static PageSort pageRequest() {
		Integer pageIndex = HttpServletUtil.getParameterInt("current", 1);
		Integer pageSize = HttpServletUtil.getParameterInt("size", pageSizeDef);
		String orderByColumn = HttpServletUtil.getParameter("orderByColumn", orderByColumnDef);
		String direction = HttpServletUtil.getParameter("isAsc", isAscDef);
		return new PageSort(pageIndex, pageSize, orderByColumn, direction);
	}

	/**
	 * @author Administrator
	 *
	 */
	public static class PageSort {
		/**
		 * 当前页
		 */
		private Integer current;

		/**
		 * 每页数量
		 */
		private Integer size;

		/**
		 * 排序字段
		 */
		private String orderByColumn;

		/**
		 * 升降序
		 */
		private String isAsc;

		public PageSort(Integer pageIndex, Integer pageSize, String orderByColumn, String direction) {
			this.current = pageIndex;
			this.size = pageSize;
			this.orderByColumn = orderByColumn;
			this.isAsc = direction;
		}

		public Integer getCurrent() {
			return current;
		}

		public void setCurrent(Integer current) {
			this.current = current;
		}

		public Integer getSize() {
			return size;
		}

		public void setSize(Integer size) {
			this.size = size;
		}

		public String getOrderByColumn() {
			return orderByColumn;
		}

		public void setOrderByColumn(String orderByColumn) {
			this.orderByColumn = orderByColumn;
		}

		public String getIsAsc() {
			return isAsc;
		}

		public void setIsAsc(String isAsc) {
			this.isAsc = isAsc;
		}

	}
}
